package com.guofen.controller.yf;

import com.guofen.pojo.RdFeed;
import com.guofen.service.yf.RdFeedService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api("研发进料表")
public class RdFeedController {
    @Resource
    private RdFeedService rdFeedService;

    /*@ApiOperation("提交进料数据现场记录")
    @PostMapping("/research/feed/add")
//    public boolean submitAllInfo(@RequestBody RdFeed rdFeed){
//        return rdFeedService.submitAllInfo(rdFeed);
//    }
    public boolean submitAllInfo(@RequestParam("feedDate") String feedDate,@RequestParam("crushStarttime") String crushStarttime,@RequestParam("crushEndtime") String crushEndtime,
                                 @RequestParam("mixStarttime") String mixStarttime,@RequestParam("mixEndtime") String mixEndtime,@RequestParam("feedStarttime") String feedStarttime,@RequestParam("feedEndtime") String feedEndtime,
                                 @RequestParam("deviceName") String deviceName,@RequestParam("batch") String batch,@RequestParam("zubie") int zubie,@RequestParam("boxNumber") int boxNumber,
                                 @RequestParam("feedWeight") double feedWeight,@RequestParam("insectResidusBoxWeight") double insectResidusBoxWeight,@RequestParam("boxWeight") double boxWeight,
                                 @RequestParam("recorder") String recorder,@RequestParam(value = "remark",defaultValue = "",required = false) String remark){
        return rdFeedService.submitAllInfo(new RdFeed(feedDate,crushStarttime,crushEndtime,mixStarttime,mixEndtime,feedStarttime,feedEndtime,deviceName,batch,zubie,boxNumber,feedWeight,insectResidusBoxWeight,boxWeight,recorder,remark));
    }*/
    @ApiOperation("获取 当日 最新 一条记录")
    @GetMapping(value = "/research/crush/getlast")
    public Result getlast(){
        return  ResultGenerator.genSuccessResult(rdFeedService.getlast());
    }

    @ApiOperation("提交粉碎记录")
    @PostMapping(value = "/research/crush/add")
    public Result addFirst(@RequestParam("save") String save,@RequestParam("feedDate") String feedDate,@RequestParam("deviceName1") String deviceName1,@RequestParam("crushStarttime") String crushStarttime,@RequestParam("crushEndtime") String crushEndtime,
                           @RequestParam("batch") String batch,@RequestParam("zubie") String zubie,@RequestParam("boxNumber") String boxNumber,
                           @RequestParam("incomingSceneMaterial") String insectResidusBoxWeight,@RequestParam("crushMaterialWeight") String crushMaterialWeight,
                           @RequestParam("recorder") String recorder,@RequestParam(value = "remark",defaultValue = "",required = false) String remark){
        return ResultGenerator.genSuccessResult(rdFeedService.addFirst(save,feedDate,deviceName1,crushStarttime,crushEndtime,batch,zubie,boxNumber,insectResidusBoxWeight,crushMaterialWeight,remark,recorder));
    }
    @ApiOperation("获取所有未进行混料的记录")
    @GetMapping(value = "/research/mix/getList")
    public Result getMixList(){
        return ResultGenerator.genSuccessResult(rdFeedService.getList());
    }
    @ApiOperation("提交混料记录")
    @PostMapping(value = "/research/mix/add")
    public Result addSecond(@RequestParam("belongToId") String belongToId,@RequestParam("deviceName2") String deviceName2,@RequestParam("mixStarttime") String mixStarttime,
                            @RequestParam("mixEndtime") String mixEndtime, @RequestParam("recorder") String recorder,@RequestParam(value = "remark",defaultValue = "",required = false) String remark){
        return ResultGenerator.genSuccessResult(rdFeedService.addSecond(belongToId,deviceName2,mixStarttime,mixEndtime,remark,recorder));
    }
    @ApiOperation("获取所有未进行进料的记录")
    @GetMapping(value = "/research/feed/getList")
    public Result getFeedList(){
        return ResultGenerator.genSuccessResult(rdFeedService.getList2());
    }

    @ApiOperation("提交进料记录")
    @PostMapping(value = "/research/feed/add")
    public Result addThird(@RequestParam("belongToId") String belongToId,@RequestParam("deviceName3") String deviceName3,@RequestParam("feedStarttime") String feedStarttime,
                           @RequestParam("feedEndtime") String feedEndtime, @RequestParam("feedWeight") String feedWeight,@RequestParam("cultivateBoxWeight") String cultivateBoxWeight,
                           @RequestParam("targetWeight") String targetWeight, @RequestParam("insectResidusBoxWeight") String insectResidusBoxWeight, @RequestParam("insectResidusWeight") String insectResidusWeight,
                           @RequestParam("recorder") String recorder,@RequestParam(value = "remark",defaultValue = "",required = false) String remark){
        return ResultGenerator.genSuccessResult(rdFeedService.addThird(belongToId,deviceName3,feedStarttime,feedEndtime,feedWeight,cultivateBoxWeight,targetWeight,insectResidusBoxWeight,insectResidusWeight,remark,recorder));
    }

    @ApiOperation("删除记录")
    @PostMapping(value = "/research/feed/delete")
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(rdFeedService.delete(id));
    }

    @ApiOperation("修改记录")
    @PostMapping(value = "/research/feed/update")
    public Result update(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id,
                         @ApiParam(name="feed_date",value="进料日期",required=true) @RequestParam String feed_date,
                         @ApiParam(name="crush_starttime",value="粉碎开始时间",required=true) @RequestParam String crush_starttime,
                         @ApiParam(name="crush_endtime",value="粉碎结束时间",required=true) @RequestParam String crush_endtime,
                         @ApiParam(name="incoming_scene_material",value="物料名称",required=true) @RequestParam String incoming_scene_material,
                         @ApiParam(name="crush_material_weight",value="粉碎物料重量",required=true) @RequestParam String crush_material_weight,
                         @ApiParam(name="mix_starttime",value="混料开始时间",required=true) @RequestParam String mix_starttime,
                         @ApiParam(name="mix_endtime",value="混料结束时间",required=true) @RequestParam String mix_endtime,
                         @ApiParam(name="feed_starttime",value="进料开始时间",required=true) @RequestParam String feed_starttime,
                         @ApiParam(name="feed_endtime",value="进料结束时间",required=true) @RequestParam String feed_endtime,
                         @ApiParam(name="device_name1",value="设备名称1",required=true) @RequestParam String device_name1,
/*                         @ApiParam(name="device_name2",value="设备名称2",required=true) @RequestParam String device_name2,
                         @ApiParam(name="device_name3",value="设备名称3",required=true) @RequestParam String device_name3,*/
                         @ApiParam(name="batch",value="批次",required=true) @RequestParam String batch,
                         @ApiParam(name="zubie",value="组别",required=true) @RequestParam Integer zubie,
                         @ApiParam(name="box_number",value="盒号",required=true) @RequestParam Integer box_number,
                         @ApiParam(name="feed_weight",value="加料重量",required=true) @RequestParam String feed_weight,
//                         @ApiParam(name="target_weight",value="目标重量",required=true) @RequestParam String target_weight,
                         @ApiParam(name="box_weight",value="培育盒重量",required=true) @RequestParam String box_weight,
//                         @ApiParam(name="insect_residus_weight",value="大虫及渣重量",required=true) @RequestParam String insect_residus_weight,
                         @ApiParam(name="insect_residus_box_weight",value="大虫及渣加盒重量",required=true) @RequestParam String insect_residus_box_weight,
                         @ApiParam(name="recorder1",value="记录人1",required=true) @RequestParam String recorder1,
                         @ApiParam(name="recorder2",value="记录人2",required=true) @RequestParam String recorder2,
                         @ApiParam(name="recorder3",value="记录人3",required=true) @RequestParam String recorder3,
                         @ApiParam(name="remark",value="备注",required=true) @RequestParam String remark) {
        RdFeed record = new RdFeed();
        double cmw = Double.parseDouble(crush_material_weight);
        double fw = Double.parseDouble(feed_weight);
//        double tw = Double.parseDouble(target_weight);
        double bw = Double.parseDouble(box_weight);
//        double irw = Double.parseDouble(insect_residus_weight);
        double irbw = Double.parseDouble(insect_residus_box_weight);

        record.setId(id);
        record.setFeedDate(feed_date);
        record.setCrushStarttime(crush_starttime);
        record.setCrushEndtime(crush_endtime);
        record.setMixStarttime(mix_starttime);
        record.setMixEndtime(mix_endtime);
        record.setFeedStarttime(feed_starttime);
        record.setFeedEndtime(feed_endtime);
        record.setDeviceName1(device_name1);
/*        record.setDeviceName2(device_name2);
        record.setDeviceName3(device_name3);*/
        record.setBatch(batch);
        record.setZubie(zubie);
        record.setBoxNumber(box_number);
        record.setCrushMaterialWeight(cmw);
        record.setFeedWeight(fw);
//        record.setTargetWeight(tw);
        record.setBoxWeight(bw);
//        record.setInsectResidusWeight(irw);
        record.setInsectResidusBoxWeight(irbw);
        record.setRecorder1(recorder1);
        record.setRecorder2(recorder2);
        record.setRecorder3(recorder3);
        record.setRemark(remark);
        return ResultGenerator.genSuccessResult(rdFeedService.update(record));
    }

    @ApiOperation("查找记录")
    @PostMapping(value = "/research/feed/select")
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间") Long startTime,
                         @ApiParam(name="endTime",value="截止时间") Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(rdFeedService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(rdFeedService.getByTime(pageSize, currentPage, startTime, endTime));
    }
}